const url = require('url');
const async = require('async');
const BaseHandler = require('../base-handler');
const SystemServices = require('../../../constants').SystemServices;
const HTTP_VERBS = require('../../../constants').HTTP_VERBS;

class GetstartedHandler extends BaseHandler {

    get pattern() {
        return "/get-started";
    }

    doGET(request, response) {
        if(!request.session.user.authenticated) {
            response.redirect('/login')
        } else {
            var logo = '/dashboard/images/sign-in-logo.png'
            var host = request.headers['host'];
            if (['localhost:3000', 'onwall-ppe.parllay.cn', 'billboards.parllay.cn'].indexOf(host) < 0) {
                logo = `/oem/${host}/images/login-logo.png`;
            }
            var source = request.query.from || undefined || request.session.user.from;
            var userId = request.session.user.id;
            var me = this;
            async.waterfall([
                (callback) => {
                    me.Controller.getWallsByUserId(userId, (walls) => {
                        callback(null, walls);
                    });
                },
                (walls) => {
                    if (walls.length > 0) {
                        response.redirect('/console');
                    } else {
                        response.render("console/get_started", {user: request.session.user, logo: logo});
                    }
                }
            ]);
        }
    }

    setup() {
        this.registerVerb(HTTP_VERBS.GET, this.doGET);
    }
}

module.exports = GetstartedHandler;